#!/bin/bash
# 
# filename: full-clone.sh
# author: rtfsc8
#
#===
WORK_DIRS=$1
CLONE_TYPE=${2:-https}

# setting target directory
[[ -z "${WORK_DIRS}" ]] && echo "Please enter workspace directory like this: $0 /mnt/work/dir" && exit

# if not exist create it
[[ ! -e ${WORK_DIRS} ]] && mkdir -p ${WORK_DIRS}

# git or https
CLONE_TYPE=$(echo ${CLONE_TYPE} | tr '[A-Z]' '[a-z]')
[[ "${CLONE_TYPE}" != "git" && "${CLONE_TYPE}" != "https" ]] && echo "Unsupport type ${CLONE_TYPE}" && exit

# clone project
cat clone-list.txt | while read url; do
  echo "Clone $url..."
# base directory name
  dirname=$(basename $url)
  if [ "${CLONE_TYPE}" == "git" ]; then
# ssh style
    url=`echo $url | sed 's#https://gitee.com/#git@gitee.com:#; s#$#.git#'`
  fi
# clone each project
  git clone $url ${WORK_DIRS}/${dirname}
  echo "Done."
done

